﻿<Settings>
  <setting name="JsonRules">
    <value>
      <![CDATA[
      {
        "RulesForEntities": [
          {
              "Key": "contact", "Value":
                {
                    "EntityName": "contact", "Rules": [
                      {
                          "Name": "sum Contact.annualincome to parent Account.revenue. Validate range is 1,000 - 200,000. On failure, set another field, send email and create task. Use Formula to calculate Credit Limit.",
                          "SourceSetting": {
                              "CrmStateCodes": [{ "Name": "Active", "Value": 0 }],
                              "FieldName": "annualincome",
                              "FieldValidators": [{
								  "ThrowExceptionWhenInvalid": "false",
                                  "Action": {
                                      "ActionField": {
                                          "CrmFieldType": "CrmOptionset",
                                          "Name": "paymenttermscode",
                                          "Value": 3
                                      },
                                      "ActionKind": "FieldAndTaskAndEmail",
                                      "EntityLogicalName": "contact"
                                  },
                                  "Range": {
                                      "MaxValue": {
                                          "CrmFieldType": "CrmMoney",
                                          "Name": "annualincome",
                                          "Value": 200000
                                      },
                                      "MinValue": {
                                          "CrmFieldType": "CrmMoney",
                                          "Name": "annualincome",
                                          "Value": 1000
                                      },
                                      "RangeValidationKind": "Range"
                                  }
                              }],
                              "FilterFetchXml": "<condition attribute='statecode' operator='ne' value='12' \/>",
                              "Formulas":[{
	                              "Name":"Set Credit Limit based on Gender and Annual Income",
	                              "ActionType":0,
	                              "Expression":"if ( [gendercode] == 1, [annualincome] * 1.5, [annualincome] * 0.7)",
	                              "FailOnMissingField":false,
	                              "OutputCrmField":{
		                              "CrmFieldType": "CrmMoney",
		                              "Name":"creditlimit",
		                              "Value":0}
	                              }],
                              "Relationship": { "ForeignKeyName": "parentcustomerid" },
                              "RollupOperation": { "OperationType": "Sum" }
                          },
                          "TargetSetting": {
                              "EntityName": "account",
                              "PrimaryKeyName": "accountid",
                              "RollupFieldName": "revenue"
                          }
                      }]
                }
          }]
    }
      ]]>
    </value>
  </setting>
</Settings>